package iblink.util;

import java.util.Calendar;
import java.util.Date;

import packutil.DateUtil;

public class IBLDateUtil extends DateUtil {

	public static Date nextTradeDate(Date d) {
		return rollTradeDate(d, true);
	}

	public static Date prevTradeDate(Date d) {
		return rollTradeDate(d, false);
	}

	private static Date rollTradeDate(Date d, boolean up) {
		Calendar c = Calendar.getInstance();
		c.setTime(d);

		do {
			c.roll(Calendar.DATE, up);
		} while (c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
				&& c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY);

		return c.getTime();
	}
}
